package controller;

import java.io.File;
import java.util.Scanner;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.widget.Toast;

/**
 * 
 * @author User
 * 
 */
public class LoadGame extends Activity {
	/**
	 * Open the last saved file and continue the game.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Read input file.

		String fileName = "__saved_game__";
		try {
			File fin = null;
			fin = new File(Environment.getDataDirectory()
					+ "/data/android.fourrows/" + fileName);
			Scanner scan = new Scanner(fin);

			int gameType = scan.nextInt();
			int numberOfMoves = scan.nextInt();
			int gameDiary[] = new int[numberOfMoves];
			for (int i = 0; i < numberOfMoves; i++) {
				gameDiary[i] = scan.nextInt();
			}

			Intent gameDisplay = new Intent(this, GameDisplay.class);
			gameDisplay.putExtra("game_type", gameType);
			gameDisplay.putExtra("number_of_moves", numberOfMoves);
			gameDisplay.putExtra("game_diary", gameDiary);
			startActivity(gameDisplay);
			finish();
		} catch (Exception e) {
			Toast.makeText(this, "Failed to load file!", 5000).show();
			finish();
		}
	}
}// End function LoadGame.
